<?php

namespace Service\Http\Controller;

use Service\Http\Exception\RestException;
use Service\Http\Request;

abstract class Controller
{

    protected function getUserObj(Request $request)
    {
        if ($request->middlewareObject['TokenAuthenticate']['Guest'] === 0) {
            return $request->middlewareObject['TokenAuthenticate']['User'];
        }
        throw new RestException('用户未登录', 403);
    }

    protected function checkUserAdminRole($user): bool
    {
        return $user['admin'] === 1;
    }

}